﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Directory.Web
{
	public partial class Admin_MessageManage : System.Web.UI.Page
	{
		protected int pageIndex = 0;
		private int pageSize = WebSettings.GetInstance().MessageViewPageSizeForAdmin;
		protected string pageKey = "page";
		private int totalRecords = 0;
		private string checkedKey = "ischecked";

		protected void Page_Load(object sender, EventArgs e)
		{
			if (!int.TryParse(Request.QueryString[pageKey], out pageIndex))
			{
				pageIndex = 0;
			}
			if (!IsPostBack)
			{
				bool ischecked;
				bool.TryParse(checkedKey, out ischecked);
				this.cbIsChecked.Checked = ischecked;

				Repeater1.DataSource = MessageBoardDataProxy.GetMessageList(cbIsChecked.Checked, pageIndex, pageSize, out totalRecords);
				Repeater1.DataBind();

				this.PageBreak.PageIndex = pageIndex;
				this.PageBreak.PageKey = pageKey;
				this.PageBreak.PageSize = pageSize;
				this.PageBreak.TotalRecords = totalRecords;
				this.PageBreak.NavigatorUrl = Request.Url.AbsolutePath + "?" + checkedKey + "=" + cbIsChecked.ToString() + "&";
			}
		}

		protected void cbIsChecked_CheckedChanged(object sender, EventArgs e)
		{
			pageIndex = 0;

			Repeater1.DataSource = MessageBoardDataProxy.GetMessageList(cbIsChecked.Checked, pageIndex, pageSize, out totalRecords);
			Repeater1.DataBind();

			this.PageBreak.PageIndex = pageIndex;
			this.PageBreak.PageKey = pageKey;
			this.PageBreak.PageSize = pageSize;
			this.PageBreak.TotalRecords = totalRecords;
			this.PageBreak.NavigatorUrl = Request.Url.AbsolutePath + "?" + checkedKey + "=" + cbIsChecked.ToString() + "&";
		}
	}
}